import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Home.vue'
import Layout from '../Layout/Layout.vue'
import store from '../store/index.js'
import '../assets/iconfont/iconfont.css'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/layout/home'
  },
  {
    path: '/layout',
    name: 'Layout',
    component: Layout,
     meta:{
            title:'首页',
            // icon:'el-icon-price-tag'
          },
    meta:{
      title:'首页',
      // icon:'el-icon-price-tag'
    },
    children:[
      {
        path: 'home',
       name: 'Home',
       component: Home,
       meta:{
         title:'首页',
         icon:'iconfont icon-weibiaoti1'
       }
      },
      {
        path: 'teacheruser',
       name: 'TeacherUser',
       component:()=>import('../views/teacheruser/TeacherUser.vue'),
       meta:{
        title:'教师管理',
        icon:'iconfont icon-wenjianbao'
      },
       children:[
         {
          path: 'teacherlist',
          name: 'TeacherList',    //教师列表
          component:()=>import('../views/teacheruser/TeacherList/TeacherList.vue'),
          meta:{
            title:'教师列表',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newteacher',
          name: 'NewTeacher',   //新增教师
          component:()=>import('../views/teacheruser/newTeacher/NewTeacher.vue'),
          meta:{
            title:'新增教师',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'teacherstry',
          name: 'TeacherStry',    //教师介绍
          component:()=>import('../views/teacheruser/TeacherStry.vue'),
          meta:{
            title:'教师介绍',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'studentuser',
       name: 'StudentUser',
       component: ()=>import('../views/studentuser/StudentUser.vue'),
       meta:{
        title:'学生管理',
        icon:'iconfont icon-boshimao'
      },
       children:[
         {
          path: 'allstudent',
          name: 'AllStudent',   //所有学生
          component: ()=>import('../views/studentuser/AllStudent.vue'),
          meta:{
            title:'所有学生',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newstudent',
          name: 'NewStudent',   //新增学生
          component: ()=>import('../views/studentuser/NewStudent.vue'),
          meta:{
            title:'新增学生',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'studentdeta',
          name: 'StudentDeta',    //学生详情
          component: ()=>import('../views/studentuser/StudentDeta.vue'),
          meta:{
            title:'学生详情',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'admincurr',
       name: 'AdminCurr',
       component: ()=>import('../views/curruser/AdminCurr.vue'),
       meta:{
        title:'课程管理',
        icon:'iconfont icon-kechengguanli'
      },
       children:[
         {
          path: 'currlist',
          name: 'CurrList',   //课程列表
          component: ()=>import('../views/curruser/CurrList.vue'),
          meta:{
            title:'课程列表',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newcurr',
          name: 'NewCurr',   //新增课程
          component: ()=>import('../views/curruser/NewCurr.vue'),
          meta:{
            title:'新增课程',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'currintroduce',
          name: 'CurrIntroduce',    //课程介绍
          component: ()=>import('../views/curruser/CurrIntroduce.vue'),
          meta:{
            title:'课程介绍',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'bookadmin',
       name: 'BookAdmin',
       component: ()=>import('../views/book/BookAdmin.vue'),
       meta:{
        title:'图书管理',
        icon:'iconfont icon-tushu'
      },
       children:[
         {
          path: 'allbook',
          name: 'AllBook',   //所有图书
          component: ()=>import('../views/book/AllBook.vue'),
          meta:{
            title:'所有图书',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newbook',
          name: 'NewBook',   //新增图书
          component: ()=>import('../views/book/NewBook.vue'),
          meta:{
            title:'新增图书',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'departmentadmin',
       name: 'DepartmentAdmin',
       component: ()=>import('../views/department/DepartmentAdmin.vue'),
       meta:{
        title:'部门管理',
        icon:'el-icon-set-up'
      },
       children:[
         {
          path: 'departmentlist',
          name: 'DepartmentList',   //部门列表
          component: ()=>import('../views/department/DepartmentList.vue'),
          meta:{
            title:'部门列表',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newdepartment',
          name: 'NewDepartment',   //新增部门
          component: ()=>import('../views/department/NewDepartment.vue'),
          meta:{
            title:'新增部门',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'admingl',
       name: 'AdminGl',
       component: ()=>import('../views/admin/AdminGl.vue'),
       meta:{
        title:'管理员管理',
        icon:'iconfont icon-bumenguanli'
      },
       children:[
         {
          path: 'adminlist',
          name: 'AdminList',   //管理员列表
          component: ()=>import('../views/admin/adminList/AdminList.vue'),
          meta:{
            title:'管理员列表',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'newadmin',
          name: 'NewAdmin',   //新增管理员
          component: ()=>import('../views/admin/newadmin/NewAdmin.vue'),
          meta:{
            title:'新增管理员',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      {
        path: 'appadmin',
       name: 'AppAdmin',
       component: ()=>import('../views/appadmin/AppAdmin.vue'),
       meta:{
        title:'应用管理',
        icon:'iconfont icon-yingyongguanli'
      },
       children:[
         {
          path: 'widget',
          name: 'Widget',   //小部件
          component: ()=>import('../views/appadmin/Widget.vue'),
          meta:{
            title:'小部件',
            icon:'el-icon-arrow-right'
          }
         },
         {
          path: 'calendar',
          name: 'Calendar',   //日历
          component: ()=>import('../views/appadmin/Calendar.vue'),
          meta:{
            title:'日历',
            icon:'el-icon-arrow-right'
          }
         },
       ]
      },
      
    ]
  }, {
    path: '/login',
    name: 'Login',   //登陆页
    component: ()=>import('../views/Login.vue')
   },
   {
    path: '/register',
    name: 'Register',   //注册页面
    component: ()=>import('../views/Register.vue')
   },
  
]

//解决vue-router在3.0版本以上重复点菜单报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



//全局前置守卫

router.beforeEach((to,from,next)=>{
  // console.log(to);
  store.commit('setRoutes',routes)
next()
})


export default router
